package com.example.common.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import lombok.Getter;

import java.util.Arrays;


@Getter
public enum GenderStatus {
    MALE("男"),
    FEMALE("女"),
    UNKNOWN("未知");
//    MALE(0, "男"),
//    FEMALE(1, "女"),
//    UNKNOWN(2, "未知");

    @EnumValue // 标识该字段为数据库存储值
//    private final int value;
    private final String desc;

    //    GenderStatus(int value, String desc) {
//        this.value = value;
//        this.desc = desc;
//    }
    GenderStatus(String desc) {
        this.desc = desc;
    }

    /**
     * 根据 value 获取对应的性别枚举
     */
//    public static GenderStatus of(int value) {
//        for (GenderStatus status : values()) {
//            if (status.getValue() == value) {
//                return status;
//            }
//        }
//        throw new IllegalArgumentException("无效的性别值: " + value);
//    }

    // 可选：根据 desc 获取枚举
    public static GenderStatus fromDesc(String desc) {
        return Arrays.stream(values())
                .filter(g -> g.getDesc().equals(desc))
                .findFirst()
                .orElseThrow(() -> new IllegalArgumentException("Invalid desc: " + desc));
    }

    // 根据 desc 获取枚举
    public static GenderStatus of(String desc) {
        return Arrays.stream(values())
                .filter(gender -> gender.getDesc().equalsIgnoreCase(desc))
                .findFirst()
                .orElseThrow(() -> new IllegalArgumentException("无效的性别值：" + desc));
    }

    /**
     * 获取默认性别（未知）
     */
    public static GenderStatus getDefault() {
        return UNKNOWN;
    }
}